<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ page import="com.hzqy.commons.utils.ConstantUtils" %>
<%@ page import="com.hzqy.web.vo.PmsUserVo" %>
<html>
<%-- <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> --%>
<link rel="stylesheet" type="text/css" href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/icon.css">
<link href="../../static/stream/css/stream-v1.css" rel="stylesheet" type="text/css">
<link href="../../static/bootstrap-3.3.5/css/bootstrap.min.css" rel="stylesheet">

<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/stream/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/stream/js/stream-v1.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>
<%
    PmsUserVo vo = ((PmsUserVo) session.getAttribute("SESSION_USER"));
    String userName = "";
    int org_id = 2;
    int status = 2;
    if (vo != null) {
        org_id = vo.getOrgId();
        //userName=vo.getOrgName();
        if (vo.getRoleIds().equals("2") || vo.getRoleIds().equals("1")) {//省公司
            status = 14;
        } else if (vo.getRoleIds().equals("3") || vo.getRoleIds().equals("10")) {//市公司
            status = 16;
        }
    }
    String[] nonceObj = ConstantUtils.getNonceObject();
%>
<head></head>
<body>
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <div class="page-header">
                <h1>行业平台视频上传 <small>upload</small></h1>

                <div id="upload_alert" class="alert alert-danger" style="font-size:15px;display:none;">
                    <a href="#" class="close" data-dismiss="alert">
                        &times;
                    </a>
                    <div id="upload_alert_inner"></div>
                </div>
                <fieldset>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td align="left" width="15%">
                                行业客户:
                            </td>
                            <td align="left" width="35%">
                                <input name="f_cc_company_name" id="f_cc_company_name" readonly="readonly"
                                       style="width: 150px;" value="<%=userName %>" class="yl_inp yw_name"/>
                                <input name="f_cc_companyid" id="f_cc_companyid" type="hidden" value="<%=org_id %>"/>
                                <input name="status" id="status" type="hidden" value="nochange"/>
                                <!-- <select id="f_cc_companyid" name="f_cc_companyid" style="width: 150px;">
                                </select> -->
                                <!-- <span id="f_cc_companyid_tip" class="tip"></span> -->
                                <a id="12" class="easyui-linkbutton" data-options="iconCls:'icon-ok'"
                                   href="javascript:void(0);"
                                   onclick="bind();">选择</a>
                            </td>
                            <td width="15%" align="right">
                                CPID:
                            </td>
                            <td width="35%">
                                <input style="width: 150px;" name="f_cc_cpid" id="f_cc_cpid" value=""
                                       class="yl_inp yw_name"/>
                            </td>
                        </tr>
                    </table>
                </fieldset>
                <fieldset>
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr>
                            <td width="15%" align="left">
                                接口类型:
                            </td>
                            <td width="15%" align="left">
                                <select name="f_cc_interfaceType" id="f_cc_interfaceType">
                                    <option value="1">华为中兴</option>
                                    <option value="2">中兴</option>
                                    <option value="3">华为</option>
                                </select>
                            </td>
                            <td class="hide-item" width="15%" align="left">
                                &nbsp;云转码输出:
                            </td>
                            <td class="hide-item" width="15%" align="left">
                                <select id="f_cc_outputType" name="f_cc_outputType">
                                    <option value="1">720*576</option>
                                    <option value="2">1280*720</option>
                                    <option value="3">1920*1080</option>
                                </select>
                            </td>
                            <td width="15%" align="right">
                                是否转码:
                            </td>
                            <td width="15%">
                                <input type="checkbox" id="f_cc_transcodeFlag_" style="width: 150px;"/>
                                <input name="f_cc_transcodeFlag" id="f_cc_transcodeFlag" type="hidden" value="0"/>
                            </td>

                    </table>
                </fieldset>
                <div class="dropzone dz-clickable" id="i_stream_dropzone">
                </div>
                <div class="btn-toolbar" role="toolbar">
                    <div class="btn-group">
                        <button type="button" class="btn btn-default" id="i_select_files">添加文件</button>
                        <button type="button" class="btn btn-default" onclick="javascript:updateData();">开始上传</button>
                        <button type="button" class="btn btn-default" onclick="javascript:_t.stop();">暂停上传任务</button>
                    </div>
                </div>

                <table id="data_table" class="table tablesorter">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>文件</th>
                        <th>大小</th>
                        <th>操作</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody id="bootstrap-stream-container">
                    </tbody>
                </table>
            </div>

        </div>
    </div>
    <div id="org_list" class="easyui-dialog"
         style="width: 800px; height: 500px; padding-top: 0px;"
         data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
        <iframe scrolling="auto" frameborder="0"
                style="width: 100%; height: 99%;"></iframe>
    </div>

    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel" style="font-weight: bold;">视频上传通知</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary" data-dismiss="modal">确认</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</div>

<!-- /.modal -->
<script type="text/javascript">
    $(function () {
        $('#myModal').modal('hide');
        $('#myModal').on('hide.bs.modal', function () {
            $(this).find('.modal-body').html('');
        });
        $("#f_cc_transcodeFlag_").change(function () {
            if ($(this).is(':checked')) {
                $("#f_cc_transcodeFlag").attr('value', '1');
            } else {
                $("#f_cc_transcodeFlag").attr('value', '0');
            }
        });
    });

    function bind() {
        openDialog($('#org_list'), '../behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_company_name');
    }

    /**
     * 配置文件（如果没有默认字样，说明默认值就是注释下的值）
     * 但是，on*（onSelect， onMaxSizeExceed...）等函数的默认行为
     * 是在ID为i_stream_message_container的页面元素中写日志
     */
    function updateData() {
        _t.upload();
    }

    var config = {
        enabled: true,
        /** 是否启用文件选择，默认是true */
        customered: true,
        multipleFiles: true,
        /** 是否允许同时选择多个文件，默认是false */
        autoRemoveCompleted: false,
        /** 是否自动移除已经上传完毕的文件，非自定义UI有效(customered:false)，默认是false */
        autoUploading: true,
        /** 当选择完文件是否自动上传，默认是true */
        fileFieldName: "FileData",
        /** 相当于指定<input type="file" name="FileData">，默认是FileData */
        maxSize: 20737418240,
        /** 当_t.bStreaming = false 时（也就是Flash上传时），2G就是最大的文件上传大小！所以一般需要 */
        simLimit: 10000,
        /** 允许同时选择文件上传的个数（包含已经上传过的） */
        extFilters: [".mp4", ".mpg", ".mpeg", ".avi", ".vob", ".wmv", ".mov", ".ts" /* ".flv", ".rm", ".rmvb", ".ts" */],
        /** 默认是全部允许，即 [] */
        browseFileId: "i_select_files",
        /** 文件选择的Dom Id，如果不指定，默认是i_select_files */
        browseFileBtn: "<div>请选择文件</div>",
        /** 选择文件的按钮内容，非自定义UI有效(customered:false) */
        dragAndDropArea: "i_stream_dropzone",
        filesQueueId: "i_stream_files_queue",
        /** 文件上传进度显示框ID，非自定义UI有效(customered:false) */
        filesQueueHeight: 450,
        /** 文件上传进度显示框的高，非自定义UI有效(customered:false)，默认450px */
        messagerId: "i_stream_message_container",
        /** 消息框的Id，当没有自定义onXXX函数，系统会显示onXXX的部分提示信息，如果没有i_stream_message_container则不显示 */
        frmUploadURL: "../../fd;",
        /** Flash上传的URI */
        uploadURL: "../../upload",
        tokenURL: "../../tk",
        onSelect: function (files) {
        },
        onMaxSizeExceed: function (file) {
            alert("文件[name=" + file.name + ", size=" + file.formatSize + "]超过文件大小限制‵" + file.formatLimitSize + "‵，将不会被上传！<br>");
        },
        onFileCountExceed: function (selected, limit) {
            $('#myModal').modal('show');
            $('#myModal .modal-body').append("同时最多上传<strong>" + limit + "</strong>个文件，但是已选择<strong>" + selected + "</strong>个<br>");
        },
        onExtNameMismatch: function (info) {
            alert("<strong>" + info.name + "</strong>文件类型不匹配[<strong>" + info.filters.toString() + "</strong>]<br>");
        },
        onAddTask: function (file) {
            var file = '<tr id="' + file.id + '" class="template-upload fade in">' +
                '<td><span class="preview">' + file.id + '</span></td>' +
                '<td><p class="name">' + file.name + '</p>' +
                '    <div><span class="label label-info">进度：</span> <span class="message-text"></span></div>' +
                '    <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">' +
                '			<div class="progress-bar progress-bar-success" title="" style="width: 0%;"></div>' +
                '		</div>' +
                '</td>' +
                '<td><p class="size">' + file.formatSize + '</p>' +
                '</td>' +
                '<td>' +
                '<div class="btn-group">' +
                //'' +
                '<button type="button" class="btn btn-xs btn-danger" onClick="javascript:_t.cancelOne(\'' + file.id + '\')"><i class="glyphicon glyphicon-remove"></i></button>' +
                '</div>' +
                '</td>' +
                '<td id="status_' + file.id + '">进行中</td>'
                + '</tr>';
            $("#bootstrap-stream-container").append(file);
        },
        onUploadProgress: function (file) {
            var $bar = $("#" + file.id).find("div.progress-bar");
            $bar.css("width", file.percent + "%");
            var $message = $("#" + file.id).find("span.message-text");
            $message.text("已上传:" + file.formatLoaded + "/" + file.formatSize + "(" + file.percent + "%" + ") 速  度:" + file.formatSpeed);


        },
        onStop: function () {
        },
        onCancel: function (file) {
            $("#" + file.id).remove();
        },
        onCancelAll: function (numbers) {
            $("#i_info_tips > span.text-message").append(numbers + " 个文件已被取消上传！！！");
        },
        onComplete: function (file) {
            /** 100% percent */
            var $bar = $("#" + file.id).find("div.progress-bar");
            $bar.css("width", file.percent + "%");
            var $message = $("#" + file.id).find("span.message-text");
            $message.text("已上传:" + file.formatLoaded + "/" + file.formatSize + "(" + file.percent + "%" + ")");
            /** remove the `cancel` button */
            var $cancelBtn = $("#" + file.id).find("td:last > span");
            $cancelBtn.remove();


            var now = new Date();
            var onLineTimeStr = now.getFullYear() + "-" + (now.getMonth() + 1) + "-01 " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();
            var offLineTimeStr = (now.getFullYear() + 10) + "-" + (now.getMonth() + 1) + "-01 " + now.getHours() + ":" + now.getMinutes() + ":" + now.getSeconds();

			var rename = eval("(" + file.msg + ")").rename;
			rename = "PIC/video/upload/content/"+rename;
            var filename = file.name.split(".")[0];

            var orgId = $('#f_cc_companyid').val();
            var f_cc_cpid = $('#f_cc_cpid').val();
            var f_cc_interfaceType = $('#f_cc_interfaceType').val();
            var f_cc_transcodeFlag = $('#f_cc_transcodeFlag').val();
            var f_cc_outputType = $("#f_cc_outputType").val();
            var params = 'videoJson=%5B%5D&f_cc_isfree=0&f_cc_status=<%=status%>&f_cc_name=' + filename + '&f_cc_searchname=&f_cc_companyid='
                + orgId + '&f_cc_tags=&sourceFlag=5&f_cc_type=2&f_cc_director=&f_cc_onlinedate=' + encodeURIComponent(onLineTimeStr)
                + '&f_cc_actors=&f_cc_offlinedate=' + encodeURIComponent(offLineTimeStr)
                + '&f_cc_screenwriter=&f_cc_code=' + encodeURIComponent(rename) + '&f_cc_seriescount=1&f_cc_end=0&picJson=%5B%5D&f_cc_desc='
                + "&f_cc_outputType=" + f_cc_outputType + "&f_cc_transcodeFlag=" + f_cc_transcodeFlag + "&f_cc_transcodePath="
                + "&f_cc_interfaceType=" + f_cc_interfaceType + "&f_cc_cpid=" + f_cc_cpid;
            app_ajax('../../content/insert_content.do', params, function (data) {
                if (data.success) {
                    $("#status_" + file.id).html("上传成功");
                    //window.location.reload();
                } else {
                    $("#status_" + file.id).html("上传失败");
                }
            });
        },
        onQueueComplete: function (msg) {
        },
        onUploadError: function (status, msg) {
            $("#i_info_tips > span.text-message").append(msg + ", 状态码:" + status);
        }
    };
    var _t = new Stream(config);
    /** 不支持拖拽，隐藏拖拽框 */
    if (!_t.bDraggable) {
        $("#i_stream_dropzone").hide();
    }
    /** Flash最大支持2G */
    if (!_t.bStreaming) {
        //_t.config.maxSize = 2147483648;
        _t.config.maxSize = 10737418240
    }
</script>
</body>
</html>
